<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<!--抽取index的head（弃用）-->
<head th:fragment="IndexHeader(title)">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:text="${title}"></title>
    <link th:href="@{/img/Bandit.ico}" rel="icon">
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet">
    <link th:href="@{/css/public.css}" rel="stylesheet">
</head>
<body>
<!--头部导航栏 MyHeader-->
<div class="layui-header" th:fragment="MyHeader" style="height: 85px">
    <ul class="layui-nav layui-bg-cyan">
        <a class="layui-logo" style="display: inline-block;">
            <img src="https://icec.nefu.edu.cn/images/logo.png">
        </a>
        <li class="layui-nav-item"><a th:href="@{/index}">首页</a></li>
        <li class="layui-nav-item"><a th:href="@{/front/lab/list}">实验室</a></li>
        <li class="layui-nav-item"><a th:href="@{/front/teachers/list}">教师队伍</a></li>
        <li class="layui-nav-item"><a th:href="@{/front/major/list}">专业方向</a></li>
        <li class="layui-nav-item">
            <a href="javascript:;">通知</a>
            <dl class="layui-nav-child">
                <dd><a th:href="@{/front/message/list/}+${MSG_TYPE_NOTICES}">公告</a></dd>
                <dd><a th:href="@{/front/message/list/}+${MSG_TYPE_NEWS}">新闻</a></dd>
                <dd><a th:href="@{/front/message/list/}+${MSG_TYPE_JOBS}">就业指南</a></dd>
            </dl>
        </li>
    </ul>
    <ul class="layui-bg-cyan layui-nav layui-layout-right" style="padding-top: 15px;margin-right: 15px">
        <li class="layui-nav-item layui-hide layui-show-lg-block" >
            <a href="javascript:;" style="display: inline-block;">

                <shiro:user>
                    <img src="https://gitee.com/lds0826/blog-image/raw/master/webImg/202112071412341.jpg" class="layui-nav-img">
                    <shiro:principal property="username" />
                </shiro:user>
                <shiro:notAuthenticated>
                    未登录
                </shiro:notAuthenticated>
            </a>
            <dl class="layui-nav-child">
                <shiro:guest>
                    <dd><a th:href="@{/login}">登录系统</a></dd>
                </shiro:guest>
                <shiro:user>
                    <dd><a th:href="@{/back/toManger}">进入管理页面</a></dd>
                    <dd><a th:href="@{/logout}">注销</a></dd>
                </shiro:user>
            </dl>
        </li>
    </ul>
</div>

<!--后台页面的Header-->
<div th:fragment="BackHeader">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">软件工程管理系统后台</div>
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a th:href="@{/index}">去前端</a></li>
<!--            <li class="layui-nav-item layui-hide-xs"><a href="#">123</a></li>-->
<!--            <li class="layui-nav-item">-->
<!--                <a href="javascript:;">456</a>-->
<!--                <dl class="layui-nav-child">-->
<!--                    <dd><a href="">menu 11</a></dd>-->
<!--                    <dd><a href="">menu 22</a></dd>-->
<!--                    <dd><a href="">menu 33</a></dd>-->
<!--                </dl>-->
<!--            </li>-->
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <!--基本资料管理-->
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">用户管理</a>
                    <dl class="layui-nav-child">
                        <shiro:hasRole name="admin">
                        <dd><a th:href="@{/back/user/list}">用户列表</a></dd>
                        <dd><a th:href="@{/back/user/add}">添加用户</a></dd>
                        <dd><a th:href="@{/back/user/visitor}">登录IP列表</a></dd>
                        </shiro:hasRole>
                        <dd><a th:href="@{/back/user/edit}">密码修改</a></dd>
                    </dl>
                </li>
                <!--信息发布管理-->
                <shiro:hasAnyRoles name="admin,normal" >
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/back/message/list}">信息列表</a></dd>
                        <dd><a th:href="@{/back/message/add}">发布一则信息</a></dd>
                    </dl>
                </li>
                </shiro:hasAnyRoles>
                <!--老师管理-->
                <shiro:hasRole name="admin">
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">老师管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/back/teachers/list}">老师列表</a></dd>
                        <dd><a th:href="@{/back/teachers/add}">添加老师</a></dd>
                    </dl>
                </li>
                <!--实验室管理-->
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">实验室管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/back/lab/list}">实验室列表</a></dd>
                        <dd><a th:href="@{/back/lab/add}">添加实验室</a></dd>
                    </dl>
                </li>
                </shiro:hasRole>
                <li class="layui-nav-item"><a th:href="@{/back/toManger}">返回欢迎页</a></li>
            </ul>
        </div>
    </div>
</div>


<!--公共脚本 pubScript-->
<div th:fragment="pubScript">
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/editor.md-master/editormd.js}"></script>
    <script th:src="@{/editor.md-master/lib/marked.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/prettify.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/raphael.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/underscore.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/sequence-diagram.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/flowchart.min.js}"></script>
    <script th:src="@{/editor.md-master/lib/jquery.flowchart.min.js}"></script>
    <script>
        layui.use(['element', 'layer', 'util'], function() {
            var element = layui.element
                , layer = layui.layer
                , util = layui.util
                , $ = layui.$;
        });
    </script>
</div>


<script th:fragment="Editor_Img">
    function initPasteDragImg(Editor){
    var doc = document.getElementById(Editor.id)
    doc.addEventListener('paste', function (event) {
            var items = (event.clipboardData || window.clipboardData).items;
            var file = null;
            console.log(items)
            console.log(items.length)
            if (items && items.length) {
                // 搜索剪切板items
                for (var i = 0; i < items.length; i++) {
                    if (items[i].type.indexOf('image') !== -1) {
                        file = items[i].getAsFile();
                        break;
                    }
                }
            }
            else {
                console.log("当前浏览器不支持");
                return;
            }
            if (!file) {
                console.log("粘贴内容非图片");
                return;
            }
            uploadImg(file,Editor);
        });
        var dashboard = document.getElementById(Editor.id)
        dashboard.addEventListener("dragover", function (e) {
            e.preventDefault()
            e.stopPropagation()
        })
        dashboard.addEventListener("dragenter", function (e) {
            e.preventDefault()
            e.stopPropagation()
        })
        dashboard.addEventListener("drop", function (e) {
            e.preventDefault()
            e.stopPropagation()
            var files = this.files || e.dataTransfer.files;
            uploadImg(files[0],Editor);
        })
    }

    function uploadImg(file,Editor){
        var formData = new FormData();
        var fileName=new Date().getTime()+"."+file.name.split(".").pop();
        formData.append('editormd-image-file', file, fileName);
        $.ajax({
            url: Editor.settings.imageUploadURL,
            type: 'post',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success: function (msg) {
                var success=msg['success'];
                if(success==1){
                    var url=msg["url"];
                    if(/\.(png|jpg|jpeg|gif|bmp|ico)$/.test(url)){
                        Editor.insertValue("![]("+msg["url"]+")");
                    }else{
                        Editor.insertValue("[下载附件]("+msg["url"]+")");
                    }
                }else{
                    console.log(msg);
                    alert("上传失败");
                }
            }
        });
    }
</script>

<script th:fragment="pwdModify">
    function oldAndRe(){
        if (newpwd.val() != repwd.val()) {
            newpwd.css("border-color", "red");
            repwd.css("border-color", "red");
            $('#newIcon').prop({"class": "layui-icon layui-icon-close", "hidden": "", "style": "color: red"});
            $('#reIcon').prop({"class": "layui-icon layui-icon-close", "hidden": "", "style": "color: red"});
        } else if (newpwd.val() == repwd.val()&&newpwd.val()!=''&&repwd.val()!='') {
            newpwd.css("border-color", "");
            repwd.css("border-color", "");
            $('#newIcon').prop({"class": "layui-icon layui-icon-ok", "hidden": "", "style": "color: green"});
            $('#reIcon').prop({"class": "layui-icon layui-icon-ok", "hidden": "", "style": "color: green"});
        }
    }
    var oldpwd = $('#oldpassword');
    var newpwd = $('#newpassword');
    var repwd = $('#repassword');
    oldpwd.on("blur",function (){
        $.ajax({
            type: 'POST',
            url: prefix + '/oldPwd',
            data:{
                "password":oldpwd.val()
            },
            success(res){
                if(res.data=="correct"){
                    console.log("密码正确")
                    oldpwd.css("border-color","");
                    $('#oldIcon').prop({"class":"layui-icon layui-icon-ok","hidden":"","style":"color: green"});
                }else if(res.data=="error") {
                    console.log("密码错误")
                    oldpwd.css("border-color","red");
                    $('#oldIcon').prop({"class":"layui-icon layui-icon-close","hidden":"","style":"color: red"});
                }else {
                    console.log("错误")
                }
            }
        })
    })
    newpwd.on("blur",function () {
        oldAndRe();
    });
    repwd.on("blur",function (){
        oldAndRe();
    });
</script>
</body>
</html>